def calcSurroundingIdxs(idxs, before, after, idxLimit=None):
	"""
	Returns (idxs - before), (idxs + after), where elements of
	idxs that result in values < 0 or > idxLimit are removed; basically,
	this is useful for extracting ranges around certain indices (say,
	matches for a substring) that are contained fully in an array.

	>>> idxs = [1, 3, 4]
	>>> calcSurroundingIdxs(idxs, 0, 0)
	([1, 3, 4], [1, 3, 4])
	>>> calcSurroundingIdxs(idxs, 1, 0)
	([0, 2, 3], [1, 3, 4])
	>>> calcSurroundingIdxs(idxs, 1, 1)
	([0, 2, 3], [2, 4, 5])
	>>> calcSurroundingIdxs(idxs, 1, 1, 4)
	([0, 2], [2, 4])
	"""
	if idxLimit is None:
		idxs = [idx for idx in idxs if (idx - before >= 0)]
	else:
		idxs = [idx for idx in idxs if (idx - before >= 0) and (idx + after <= idxLimit)]
	beforeIdxs = [x - before for x in idxs]
	afterIdxs = [x + after for x in idxs]
	return beforeIdxs, afterIdxs