def cropToAspectRatio(frame, size):
    """
    Crop the frame to desired aspect ratio and then scales it down to desired size
    Args:
        frame (numpy.ndarray): Source frame that will be cropped
        size (tuple): Desired frame size (width, height)
    Returns:
         numpy.ndarray: Cropped frame
    """
    shape = frame.shape
    h = shape[0]
    w = shape[1]
    currentRatio = w / h
    newRatio = size[0] / size[1]

    # Crop width/height to match the aspect ratio needed by the NN
    if newRatio < currentRatio:  # Crop width
        # Use full height, crop width
        newW = (newRatio/currentRatio) * w
        crop = int((w - newW) / 2)
        return frame[:, crop:w-crop]
    else:  # Crop height
        # Use full width, crop height
        newH = (currentRatio/newRatio) * h
        crop = int((h - newH) / 2)
        return frame[crop:h-crop, :]