The matrix equation $AX-XB=C$ has a solution if and only if the matrices [A&C0&B] and [A &00 & B] are similar. This criterion was proved over a field by W.E. Roth (1952) and over the skew field of quaternions by Huang Liping (1996). H.K. Wimmer (1988) obtained an analogous criterion for the matrix equation $X-AXB=C$ over a field. We extend these criteria to the matrix equations $AX-widehat XB=C$ and $X-Awidehat XB=C$ over the skew field of quaternions with a fixed involutive automorphism $qmapsto hat q$.