Long-term variations in the magnetic field of the Sun and possible implications for terrestrial climate