How can I get neighbour frames when implementing my own ffmpeg filter?

I'm implementing a custom FFmpeg filter. When frame N is processing, I hope I can also get the information of frame N-1 and frame N+1. Is there any FFmpeg function I could use for some help?

In my custom FFmpeg filter, the filter_frame function provides an AVFrame object, which is the Nth frame, but how can I get the former and the latter AVFrame object.

static int filter_frame(AVFilterLink *link, AVFrame *in)