Oh yes, I forgot to check that part of the code. Replacing the erosion operation with an opening operation yielded the desired result.
img = cv2.GaussianBlur(img, (11, 11), 0)
kernel = np.ones((11, 11), np.uint8)
morph_open = cv2.morphologyEx(img, cv2.MORPH_OPEN, kernel, iterations=1)
img = cv2.absdiff(img, morph_open)
img = cv2.threshold(img, 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU)[1]