You could do it by working off the same ideas as affine gap alignment (see these random lecture notes or these ones).
The affine gap algorithm uses three dynamic programming matrices to optimize the alignment: (1) the best score of two prefixes that ends in an aligned character, (2) the best score of two prefixes where the first sequence is in a gap, and (3) the best score of two prefixes where the second sequence is in a gap. The transitions and scores are set up so that you pay an extra penalty when you open a gap (move from matrix 1 to 2 or 3), but not when you lengthen an existing gap (stay in matrix 2 or matrix 3).
So based on those ideas, you would need a matrix for each possible distance since the last gap in each sequence (0, 1, 2, 3, 4, or 5+), for each of the two sequences. You could set up the transitions so that each additional aligned character goes "up" a matrix (for example matrix 3 to matrix 4, then matrix 4 to matrix 5+, and finally staying in matrix 5+). You would pay an extra penalty for adding a gap near a previous one (going from matrix 1-4 to 0), but not after you're sufficiently far away (matrix 5+ to 0).
There are a lot of details, and in general it might be annoying to implement. And, as some of the other answers suggest, it's not clear if it's a valid assumption or what it might correspond to biologically. But it can be done, and in the same time complexity as standard Smith-Waterman alignment as long as the maximum tracked inter-gap distance is regarded as a constant.