In millisecond pulsars the existence of the Coriolis force allows the development of the so-called Rossby oscillations (r-modes) which are know to be unstable to emission of gravitational waves. These instabilities are mainly damped by the viscosity of the star or by the existence of a strong magnetic field. A fraction of the observed millisecond pulsars are known to be inside Low Mass X-ray Binaries (LMXBs), systems in which a neutron star (or a black hole) is accreting from a donor whose mass is smaller than 1 $M_odot$. Here we show that the r-mode instabilities can generate strong toroidal magnetic fields by inducing differential rotation. In this way we also provide an alternative scenario for the origin of the magnetars.