Thanks!
It is not a trick, it's what's called a Sensor fusion algorithm. They come in many flavors, we currently implement Madgwick's one. Another popular and somehow more robust alternatives are Kalman filters, we'll probably also implement one of those in the future.
They all rely on absolute references (gravity and magnetic field) to build a non-drifting reference frame which is used to correct the integration of (angular) accelerations.