ar_track_alvar rotation changes suddenly
I had that problem that some markers get detected as their mirrored version and then suddenly get a flipped z axis facing the rear side. Same as @Mehdi. How could you solve this? which orentation is right?
Well they should always be facing the camera otherwise it wouldn't make sense, so check the quaternion range of markers with a Z vector facing the camera and try to get some threshold.