Implement av_nearer_q() and av_find_nearest_q_idx() functions.