Pose mirroring wrong

Hello, Blender newbie here. I have a problem mirroring poses that’s giving me a headache. When I mirror for example the left leg the right leg isn’t correctly mirrored, it’s rotated for some reason.

I’ve read possible solutions and watched some videos, but I still get bad results.

This is what I do.
First I create the bones I need.


I place the 3D cursor at (0, 0, 0).
I select all of them except torso and head bones. I press SHIFT+D, ESC, CTRL+M, X, ENTER
to create a mirrored copy. Then I press W and select flip names.


Once that is done, I go to pose mode and move some bones on the right side:


Then, with those bones selected, I press CTRL+C, CTRL+SHIFT+V to paste mirrored,
but this is what happens.


What could I possibly be doing wrong?