And with enough sensors (4 magnetometers) you can reconstruct 3D trajectory.
The following thesis is fascinating and very instructive: http://pastel.archives-ouvertes.fr/docs/00/50/10/05/PDF/pdfV...
Chapter 5 is very instructive, in particular the section Measuring magnetic fields gradients to derive velocity.
Excerpts: If the body moves, then the sensed magnetic field must change according to Maxwell’s equations. If the magnetic measurements do not change significantly, then the solid body is not moving. This permits us to rule out velocity drifts in our estimation. Ultimately, this improves the position information obtained by integrating the velocity estimate.
Note that they don't use the raw magnetic field, but its gradients, i.e a physical quantity that is intrinsequely local. Filtering out the earth's magnetic fields becomes quite easy (I suppose..) since these gradients are fast-varying quantities in comparison. Kind of like when you use an accelerometer: gravity is low-frequency, motions are high-frequency.