Help with optimization opencv videocapture optical flow analysis

If someone would be so kind as to check something for me in my code:

When skip is set to 30 then does it compare every 30th frame with each other? i Think so right?

So what i hope is that i have coded the following:
Frame 1 is compared with frame 31.
Frame 31 is compared with frame 61.
Frame 61 is compared with frame 91, and so on.

def calculate_movement(video_file):
    global pbar  # Access the global progress bar
    cap = cv2.VideoCapture(video_file)
    fps = cap.get(cv2.CAP_PROP_FPS)

    movement_percentages = []
    counter = 0

    # Get the first frame
    ret, frame = cap.read()
    if not ret:
        return [], fps

    frame_gpu = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
    prvs = frame_gpu

    # Get the original size of the frames
    frame_size = (prvs.shape[1], prvs.shape[0])

    # Initialize optical flow object
    optical_flow = cv2.cuda_NvidiaOpticalFlow_2_0.create(
        frame_size, 
        cv2.cuda.NvidiaOpticalFlow_2_0_NV_OF_PERF_LEVEL_SLOW, 
        cv2.cuda.NvidiaOpticalFlow_2_0_NV_OF_OUTPUT_VECTOR_GRID_SIZE_4, 
        cv2.cuda.NvidiaOpticalFlow_2_0_NV_OF_HINT_VECTOR_GRID_SIZE_4, 
        False, 
        False, 
        False, 
        device_id
    )

    while True:
        counter += 1
        ok = cap.grab()
        if not ok:
            break

        # Only decode and process every skip-th frame
        if counter % skip == 0:
            ret, frame = cap.retrieve()
            if not ret:
                break