We describe a computationally efficient heuristic algorithm based on a renormalization-group procedure which aims at solving the problem of finding a minimal surface given its boundary (curve) in any hypercubic lattice of dimension D > 2. We use this algorithm to correct errors occurring in a four-dimensional variant of the toric code, having open as opposed to periodic boundaries. For a phenomenological error model which includes measurement errors we use a five-dimensional version of our algorithm, achieving a threshold of 4.35 ± 0.1%. For this error model, this is the highest known threshold of any topological code. Without measurement errors, a four-dimensional version of our algorithm can be used and we find a threshold of 7.3 ± 0.1%. For the gate-based depolarizing error model, we find a threshold of 0.31 ± 0.01% which is below the threshold found for the two-dimensional toric code.