def rescale_boxes(boxes, current_dim, original_shape):
    """ Rescales bounding boxes to the original shape """
    orig_h, orig_w = original_shape
    pad_x = max(orig_h - orig_w, 0) * (current_dim / max(original_shape))
    pad_y = max(orig_w - orig_h, 0) * (current_dim / max(original_shape))
    unpad_h = current_dim - pad_y
    unpad_w = current_dim - pad_x
    boxes[:, (0)] = (boxes[:, (0)] - pad_x // 2) / unpad_w * orig_w
    boxes[:, (1)] = (boxes[:, (1)] - pad_y // 2) / unpad_h * orig_h
    boxes[:, (2)] = (boxes[:, (2)] - pad_x // 2) / unpad_w * orig_w
    boxes[:, (3)] = (boxes[:, (3)] - pad_y // 2) / unpad_h * orig_h
    return boxes
