Shadows flicker (Shadow Mapping)

I’m looking to improve my shadows again. Basically the shadows I have work really well (good detail) when I’m only rendering small portions of my scene. Problem is I have a big world so obviously if I try to render the shadow map over the world I get very boxy shadows.

I thought a decent way to remedy this would be to only render the shadow map to a 40x40 area around the camera (I don’t have any decent frustum logic to help with sizes):

		glOrtho(-20.0f + main_cam.getPosition().m_x, 
					20.0f + main_cam.getPosition().m_x, 
				   -20.0f + main_cam.getPosition().m_z, 
				    20.0f + main_cam.getPosition().m_z, 
				    0.1f, 1000.0f);

However, this leads to the shadows flickering when the camera is moving, why does the flickering occur?