Switching to LAND mode automatically using EKF3

I am implementing an optical flow camera to help the drone’s stability when GPS is not available. After a few minutes of flying the drone, it switches to LAND mode and reduces the rotors’ power until it lands.

I am using EKF3 to integrate the flow camera and switch the position source from GPS to the flow camera. I was worried that might have been caused by the EKF3 failsafe but when using only GPS (not switching to flow camera) seems to have the same effect, switch to LAND mode.

My concern is that the rangefinder implemented in the optical flow is giving sometimes inconsistent values that might cause the Z innovation in the EKF3 to trigger the failsafe.
But also the logs trigger EKF_YAW_RESSET so the issue might be some compass decalibration produced by the motors. I read in some other forums to use Magfit to calibrate the compass.
Any suggestions of what might be the cause of the problem ?

I have attached logs of 2 flights:
1.Optical Flow with RangeFinder

  1. Optical Flow with Barometer (timestamp 10:00 - 13:00)