Processing and output of video frames

I display the frames of two videos by the following code:

import numpy as np
import cv2
import matplotlib.pyplot as plt
from utils.plot_image_utils import plot_images

# Create a VideoCapture object and read from input file
cap = cv2.VideoCapture('first.mp4', 0)
cap2 =cv2.VideoCapture('second.mp4', 0)

while(cap.isOpened()|cap2.isOpened()):
    ret, frame = cap.read()
    ret1, frame1 = cap2.read()
    if ret == True and ret1 == True:
       src_image_example = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
       tar_image_example = cv2.cvtColor(frame1, cv2.COLOR_BGR2RGB)
       plot_images(src_image_example, tar_image_example)

if cv2.waitKey(1) & 0xFF == ord('q'):
  break

cap.release()
cap2.release()
cv2.destroyAllWindows()

Explain me please, why, after further certain processing of the whole frames, only the last frames are output at the end?
Or after the

cv2.destroyAllWindows ()

command all previous frames are removed from the memory?

what does it do ? please add resp. code

it’s unclear, what you mean here. can you try to explain, what you expect, and what happens ?

This is the function which just plots the frames:

def plot_images(img1, img2=None, title=""):
plt.subplot(1, 2, 1)
plt.imshow(img1, vmin=0, vmax=255, cmap=plt.cm.gray)
plt.title("Source Image" + title, fontsize=7)
if img2 is not None:
plt.subplot(1, 2, 2)
plt.imshow(img2, vmin=0, vmax=255, cmap=plt.cm.gray)
plt.title("Target Image", fontsize=7)
plt.show()

After displaying all the frames of two videos I generate a scaling object that saves the scaling matrices. Then I generate the image that should correspond to the original source frame (image). Then I downscale this generated image that should correspond to the target frame (image). And then I just want to plot both all the generated images and target output images. But it seems like the output is only the last frames.