There are several issues.
1.) The points are not ordered correctly for your formula to work. I guess they should be ordered like: (points should be ordered such, that you have a line of the rectangle between two points that are adjacent in the list and the last and first entry in the list)
points = [[183, 291], [378, 387], [479, 150], [317, 80]]
2.) There is a mistake in your formula. (I guess the formula should be the one, that finds the mid point of a line or in this case the midpoint of a diagonal between point 0 and point 2).
It should be
cx = (coord[idx1][0] + coord[idx2][0]) / 2
cy = (coord[idx1][1] + coord[idx2][1]) / 2
where idx1, idx2 are either 0,2 or 1,3
For a rectangle cx, cy will be identical regardless of whether you use idx1=0, idx2=2 or idx1=1, idx2=3
3.) This formula (midpoint of a diagonal) determines the centroid only for rectangles. What you have is a quadrangle, which is almost, but not exactly a rectangle, so the formula does not apply at all.
Try to calculate cx, cy with idx1, idx2 = 0, 2 and with idx1, idx2 = 1, 3
and you see, that you get different results. Thus you do not have a rectangle.
Either there is a typo in the coordinates, that you posted, or perhaps there is an error in the formula that calculated your rectangle or your question really meant to calculate the centroid of a quadrangle, which is different.
In that case it might be advisable to adapt the title of the question
You can find the formula for a polygon here https://en.wikipedia.org/wiki/Centroid#Of_a_polygon