The easiest approach without changing your code too much is probably to add conditions based on the current layer:
def forward(self, x):
    pool_idx = []
    for layer in self.module_list:
        if isinstance(layer, nn.MaxPool2d):
            ...
            pool_idx.append(idx)
        elif isinstance(layer, nn.MaxUnpool2d):
            idx = pool_idx.pop(-1)
            ...
        else:
            ...