def matching_and_reshaping(o_tensor, p_tensor):
    """
    Matching the shape of object hidden feature and person hidden feature.
    
    Args:
        o_tensor (Tensor): object hidden feature has shape (N, C, Hi, Wi),
            where axes 0-3 are the number of images in batch, channels, height, and width.
        p_tensor (Tensor): person hidden feature has shape (N, C, K),
            where k is number of person anchors.

    This function contains the following operations:
        1. Reshape `o_tensor` from (N, C, Hi, Wi) to (N, C, Hi * Wi)
        2. Repeat `o_tensor` to shape (N, C, Hi * Wi, K) to match with number of person anchors.
        3. Repeat `p_tensor` to shape (N, C, Hi * Wi, K) to match with `o_tensor`.
        4. Move 1-th axis to the last. This step is for the subsequent fc layers, where
           the last axis should be channels.
    """
    n1, c1, h, w = o_tensor.size()
    n2, _, k = p_tensor.size()
    assert n1 == n2, "Must have the same number of images"

    o_tensor = o_tensor.view(n1, c1, -1).unsqueeze(3).repeat(1, 1, 1, k)
    p_tensor = p_tensor.unsqueeze(2).repeat(1, 1, w * h, 1)

    o_tensor = o_tensor.permute(0, 2, 3, 1)
    p_tensor = p_tensor.permute(0, 2, 3, 1)

    return o_tensor, p_tensor