def GetMatchingOutputShapes(model, batch, layers):
    """
    Function to find matching layers for merge by concatenation. Matching layers have same output shape with respect
    to spatial dimention only

    Args:
        model: CNN model
        batch: first batch of the train loader
        layers: model layers

    Returns:
        Returns a list of matching layer pairs as indices, not ID's!!! 
    """

    allowed_layer_types4connection = {'ReLU', 'MaxPool2d'}

    # Use the first batch to get relavent information about the layers
    model.forward(batch)

    matching_layers = []

    for layer_idx1 in layers:
        for layer_idx2 in layers:

            id1 = str(layer_idx1["id"])
            id2 = str(layer_idx2["id"])

            # Do not use the input layers
            if id1 != "0" and id2 != "0" and id1 != id2:

                if (model._modules[id1].__class__.__name__ in allowed_layer_types4connection) \
                        and (model._modules[id2].__class__.__name__ in allowed_layer_types4connection):

                    # All shapes must match
                    if model.layerdic[id1].size()[1] == model.layerdic[id2].size()[1]:
                        if model.layerdic[id1].size()[2] == model.layerdic[id2].size()[2]:
                            if model.layerdic[id1].size()[3] == model.layerdic[id2].size()[3]:
                                matching_layers.append([id1, id2])

    return matching_layers