Character animation rig problem

The knees bend sideways instead of forward and backward(normal) I tried: “Recalculate Roll > View Axis” but that didn’t do anything. How to fix it?
I’m not sure how to embed the GIF: http://i.imgur.com/RnafzSD.gif

I figure it out. The problem was with the pole angle. I set one to 0 and the other to 180 and somehow for some reason, it worked properly.