Using the Methodic Configurator software and calibrate the imu and gyro drift (steps 02 and 03) and the in flight mag fit (steps 21 and 22) after that the imu and compass should be consistent.
Or at least reduce the amount of times that they are inconsistent.
okhh pixhawk uses only one compass at a time if that fails then it uses second in the priority list
So i would recommend to set priority to external compass and recalibrate because as i can see the pixhawk compass is close to the bed and surrounded by wire and prone to interference btw your gps have enough clearance. Try this method first
If still that throw an error then you can use advance calibration as described above by @amilcarlucas .