Fix HoughLines crashes (Bug #3959).

Avoid phi exceed PI/2 to get the negative value of cos(phi).